package com.kkb.controller;

import com.github.pagehelper.PageInfo;
import com.kkb.pojo.PricePeople;
import com.kkb.service.HospitalizationService;
import com.kkb.service.PricePeopleService;
import com.kkb.vo.PricePeopleQueryVO;
import com.kkb.vo.ResultVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Controller
@ResponseBody
@RequestMapping("pricePeople")
public class PricePeopleController {

    @Resource
    PricePeopleService service;

    @Resource
    HospitalizationService hospitalizationService;

    @RequestMapping(value = "", method = RequestMethod.POST)
    public ResultVO add(PricePeople pricePeople) {
        pricePeople.setInTime(new Date());
        int result = service.add(pricePeople);

        return result == 1 ? new ResultVO("新增成功!") : new ResultVO(500, "新增失败!");
    }

    @RequestMapping(value = "list", method = RequestMethod.GET)
    public ResultVO queryAll(int index, int size, PricePeopleQueryVO vo) {
        PageInfo pageInfo = service.queryAll(index, size, vo);
        return new ResultVO(pageInfo);
    }

    @RequestMapping(value = "/people/{id}", method = RequestMethod.GET)
    public ResultVO queryByPatientId(@PathVariable("id") int id) {
        List list = service.queryByPatientId(id);
        if (list == null) {
            return new ResultVO(500, "服务器异常!");
        } else {
            return new ResultVO(list);
        }
    }

}
